//
//  StatusOriginalView.swift
//  WeiBo_test
//
//  Created by 张leslie45 on 16/1/22.
//  Copyright © 2016年 张leslie45. All rights reserved.
//

import UIKit
import SnapKit
class StatusOriginalView: UIView {
    
    var status: Status? {
        didSet {
            //绑定数据
            headImage.sd_setImageWithURL(status?.user?.headImageURL, placeholderImage: UIImage(named: "avatar_default_big"))
            nameLabel.text = status?.user?.name
            mbrankImage.image = status?.user?.mbrank_image
            verifiedTypeImage.image = status?.user?.verified_type_image
            timeLabel.text = status?.created_at
            sourceLabel.text = status?.source
            contentLabel.text = status?.text
            //传递 配图视图的数据源
            pictureView.imageURLs = status?.imageURLs
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
    
       backgroundColor = UIColor(white: 0.95, alpha: 1)
       addSubview(headImage)
        addSubview(nameLabel)
        addSubview(mbrankImage)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(verifiedTypeImage)
        addSubview(contentLabel)
        addSubview(pictureView)
    
        //设置约束
        headImage.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.size.equalTo(CGSize(width: StatusCellImageWidth, height: StatusCellImageWidth))
            
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImage.snp_top)
            make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)
        }
        
        mbrankImage.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(headImage.snp_bottom)
            
        }
        
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(timeLabel.snp_bottom)
        }
        
        verifiedTypeImage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImage.snp_right)
            make.centerY.equalTo(headImage.snp_bottom)
        }
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(headImage.snp_left)
            //            make.right.equalTo(self.snp_right).offset(-StatusCellMargin)
            make.top.equalTo(headImage.snp_bottom).offset(StatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            //iOS 9之后 必须是 left -> left  right -> right
            make.left.equalTo(headImage.snp_left)
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            //TODO: 后续修改 先给定测试大小
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
           // 设置一个非常关键的属性,就可以实现视图的行高自动获取
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin)
        }
        
    }
    
    
//懒加载所有的子视图
    private lazy var headImage:UIImageView = UIImageView()
    private lazy var nameLabel:UILabel = UILabel(title: "隔壁老王", fontSize: 14, color: themeColor)
  
//   用户等级
    private lazy var mbrankImage:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
//   微博时间
    private lazy var timeLabel:UILabel = UILabel (title: "23:23", fontSize: 10, color: UIColor.lightGrayColor())
//   微博来源
    private lazy var sourceLabel:UILabel = UILabel(title: "22期的同学们", fontSize: 10, color: UIColor.lightGrayColor())
    
//   微博谁类型
    private lazy var verifiedTypeImage:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
//   微博正文
    private lazy var contentLabel:UILabel = UILabel(title: "听说下雨天音乐和巧克力更配哦~~~", fontSize: 14, color: UIColor.darkGrayColor(), margin: StatusCellMargin)
    
//   配图视图
    private lazy var pictureView:StatusCellPictureView = StatusCellPictureView()
 
  
}
